<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
</head>
<body>
    <div id="app">
        <table>
            <tr>
                <td>姓名：</td>
                <td><input type="text" v-model.trim="user.name"></td>
            </tr>
            <tr>
                <td>年龄：</td>
                <td><input type="text" v-model.number="user.age"></td>
            </tr>
            <tr>
                <td>住址：</td>
                <td><input type="text" v-model.lazy="user.addr"></td>
            </tr>
            <tr>
                <td>电话号码：</td>
                <td><input type="text" v-model="user.tel" @keyup.f4="window"></td>
            </tr>
        </table>
        <button v-if="!isShow" @click="isShow = !isShow">打印信息</button>
        <table v-if="isShow" class="info">
            <tr>
                <th>姓名</th>
                <th>年龄</th>
                <th>地址</th>
                <th>电话</th>
            </tr>
            <tr>
                <td>{{ user.name }}</td>
                <td>{{ user.age }}</td>
                <td>{{ user.addr }}</td>
                <td>{{ user.tel }}</td>
            </tr>
        </table>
        <p></p>
        <div id="demo" v-change>
            内容
        </div>
    </div>
    <script>
        new Vue({
            el: "#app",
            data: {
                user: {
                    name: "",
                    age: "",
                    addr: "",
                    tel: ""
                },
                isShow: false
            },
            methods: {
                window() {
                    alert(this.user.tel)
                }
            },
            directives: {
                change: {
                    bind: (el, binding) => {
                        el.style = 'background-color: yellow'
                    }
                }
            }
        })
    </script>
    <style>
        .info {
            border-collapse: collapse;
        }
        .info td, th {
            border: 1px solid #ccc;
            min-width: 50px;
        }
        #demo {
            width: 350px;
            height: 200px;
            border: 1px solid #000;
        }
    </style>
</body>
</html>